package com.sanbi.shield.server.controller;

import com.sanbi.common.vo.ResponseVo;

import com.sanbi.shield.server.biz.param.LoginParam;
import com.sanbi.shield.server.biz.service.AdminService;
import com.sanbi.shield.server.jdbc.domain.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.security.auth.Subject;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * @desc 权限控制Controller
 * @author wanggang
 * @time 2024/9/14 13:42
 */
@Validated
@RestController
@RequestMapping("auth")
public class AuthController {
    @Autowired
    private AdminService adminService;

    /**
     * @desc 登录接口
     * @author wanggang
     * @time 2024/9/14 13:44
     */
    @PostMapping("login")
    public ResponseVo login(@RequestBody @Validated LoginParam loginParam, HttpServletRequest request) {
        Admin admin=adminService.login(loginParam);

        Map<String, Object> adminInfo = new HashMap<>();
        adminInfo.put("nickName", admin.getUsername());
        adminInfo.put("avatar", admin.getAvatar());
        adminInfo.put("country_id", admin.getRegisterCountryId());
        Map<Object, Object> result = new HashMap<>();
        result.put("token", admin.getToken());
        result.put("adminInfo", adminInfo);

        return ResponseVo.ok(result);
    }

}
